﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using prjKQXS_DLL;
using prjKQXS_DLL.Ve_so;
using prjKQXS_DLL.Hop_dong;
using prjKQXS_Report.Truyen_thong;
using DevExpress.XtraSplashScreen;
using DevExpress.XtraReports.UI;
using DevExpress.XtraGrid;
using prjKQXS_Report.Boc;
using System.Collections;

namespace prjKQXS_UI.Boc
{
    public partial class frmQuayveboc5 : DevExpress.XtraEditors.XtraForm
    {
        public frmQuayveboc5()
        {
            InitializeComponent();
        }

        private Dictionary<string,string> lstQuaySo;
        private void frmQuayveboc5_Load(object sender, EventArgs e)
        {
            lstQuaySo = new Dictionary<string, string>()
            {
               {"txtnhat1",""},{"txtnhat2",""},{"txtnhat3",""},{"txtnhat4",""},
               {"txtnhi1",""},
               {"txtba1",""},
               {"txttu1",""},{"txttu2",""},{"txttu3",""},{"txttu4",""},
               {"txttu5",""},{"txttu6",""},{"txttu7",""},{"txttu8",""},
               {"txttu9",""},{"txttu10",""},{"txttu11",""},{"txttu12",""},
               {"txttu13",""},{"txttu14",""},{"txttu15",""},{"txttu16",""},
               {"txtnam1",""}
            };
            deNgay.DateTime = BienTc.denngay;
            txtgiave.Text = BienTc.GiaVe.ToString();
            txtkyhieu.Text = BienTc.KyHieuVe;
            txtnhat1.Mask = "0000";
            txtnhat2.Mask = "0000";
            txtnhat3.Mask = "0000";
            txtnhat4.Mask = "0000";
            txtnhi1.Mask = "000";
            txtba1.Mask = "000";
            txttu1.Mask = "00";
            txttu2.Mask = "00";
            txttu3.Mask = "00";
            txttu4.Mask = "00";
            txttu5.Mask = "00";
            txttu6.Mask = "00";
            txttu7.Mask = "00";
            txttu8.Mask = "00";
            txttu9.Mask = "00";
            txttu10.Mask = "00";
            txttu11.Mask = "00";
            txttu12.Mask = "00";
            txttu13.Mask = "00";
            txttu14.Mask = "00";
            txttu15.Mask = "00";
            txttu16.Mask = "00";
            txtnam1.Mask = "0";
            if (!dmcanbo_dal.Kiemtrakyhieuboc(BienTc.KyHieuVe))
            {
                dong = false;
                Hienthiketqua();
                Thuoctinh();
            }
            else
            {
                txtnhat1.Focus();
                dong = true;
                Thuoctinh();
            }
        }
        public bool dong = false;
        private void Thuoctinh()
        {
            if (dong == false)
            {
                txtnhat1.Enabled = false;
                txtnhat2.Enabled = false;
                txtnhat3.Enabled = false;
                txtnhat4.Enabled = false;
                txtnhi1.Enabled = false;
                txtba1.Enabled = false;
                txttu1.Enabled = false;
                txttu2.Enabled = false;
                txttu3.Enabled = false;
                txttu4.Enabled = false;
                txttu5.Enabled = false;
                txttu6.Enabled = false;
                txttu7.Enabled = false;
                txttu8.Enabled = false;
                txttu9.Enabled = false;
                txttu10.Enabled = false;
                txttu11.Enabled = false;
                txttu12.Enabled = false;
                txttu13.Enabled = false;
                txttu14.Enabled = false;
                txttu15.Enabled = false;
                txttu16.Enabled = false;
                txtnam1.Enabled = false;
            }
            else
            {
                txtnhat1.Enabled = true;
                txtnhat2.Enabled = true;
                txtnhat3.Enabled = true;
                txtnhat4.Enabled = true;
                txtnhi1.Enabled = true;
                txtba1.Enabled = true;
                txttu1.Enabled = true;
                txttu2.Enabled = true;
                txttu3.Enabled = true;
                txttu4.Enabled = true;
                txttu5.Enabled = true;
                txttu6.Enabled = true;
                txttu7.Enabled = true;
                txttu8.Enabled = true;
                txttu9.Enabled = true;
                txttu10.Enabled = true;
                txttu11.Enabled = true;
                txttu12.Enabled = true;
                txttu13.Enabled = true;
                txttu14.Enabled = true;
                txttu15.Enabled = true;
                txttu16.Enabled = true;
                txtnam1.Enabled = true;
            }
        }
        private void Luuketqua()
        {
            try
            {

                DMVETT dmveboc = new DMVETT();
                dmveboc.Kyhieu = txtkyhieu.Text;
                dmveboc.Giave = 10000;
                //dmveboc.Giave = (Int32)clsCommon.Parse(txtgiave.Text, 0);
                dmveboc.Ngaymothuong = (DateTime)clsCommon.Parse(deNgay.Text, 4);
                dmveboc.gnhat1 = txtnhat1.Text.ToString().Trim();
                dmveboc.gnhat2 = txtnhat2.Text.ToString().Trim();
                dmveboc.gnhat3 = txtnhat3.Text.ToString().Trim();
                dmveboc.gnhat4 = txtnhat4.Text.ToString().Trim();
                dmveboc.gnhi1 = txtnhi1.Text.ToString().Trim();
                dmveboc.gba1 = txtba1.Text.ToString().Trim();
                dmveboc.gtu1 = txttu1.Text.ToString().Trim();
                dmveboc.gtu2 = txttu2.Text.ToString().Trim();
                dmveboc.gtu3 = txttu3.Text.ToString().Trim();
                dmveboc.gtu4 = txttu4.Text.ToString().Trim();
                dmveboc.gtu5 = txttu5.Text.ToString().Trim();
                dmveboc.gtu6 = txttu6.Text.ToString().Trim();
                dmveboc.gtu7 = txttu7.Text.ToString().Trim();
                dmveboc.gtu8 = txttu8.Text.ToString().Trim();
                dmveboc.gtu9 = txttu9.Text.ToString().Trim();
                dmveboc.gtu10 = txttu10.Text.ToString().Trim();
                dmveboc.gtu11 = txttu11.Text.ToString().Trim();
                dmveboc.gtu12 = txttu12.Text.ToString().Trim();
                dmveboc.gtu13 = txttu13.Text.ToString().Trim();
                dmveboc.gtu14 = txttu14.Text.ToString().Trim();
                dmveboc.gtu15 = txttu15.Text.ToString().Trim();
                dmveboc.gtu16 = txttu16.Text.ToString().Trim();
                dmveboc.gnam1 = txtnam1.Text.ToString().Trim();
                dmcanbo_dal.InsertDMVEBOC(dmveboc);
            }
            catch
            {

            }
        }

        private void Hienthiketqua()
        {
            try
            {
                DMVETT dmveboc = new DMVETT();
                dmveboc.Kyhieu = txtkyhieu.Text;
                dmveboc.Giave = (Int32)clsCommon.Parse(txtgiave.Text, 0);
                dmveboc.Ngaymothuong = (DateTime)clsCommon.Parse(deNgay.Text, 4);
                txtnhat1.Text = dmcanbo_dal.SelectDMVEBOC("gnhat1", dmveboc.Kyhieu);
                txtnhat2.Text = dmcanbo_dal.SelectDMVEBOC("gnhat2", dmveboc.Kyhieu);
                txtnhat3.Text = dmcanbo_dal.SelectDMVEBOC("gnhat3", dmveboc.Kyhieu);
                txtnhat4.Text = dmcanbo_dal.SelectDMVEBOC("gnhat4", dmveboc.Kyhieu);
                txtnhi1.Text = dmcanbo_dal.SelectDMVEBOC("gnhi1", dmveboc.Kyhieu);
                txtba1.Text = dmcanbo_dal.SelectDMVEBOC("gba1", dmveboc.Kyhieu);
                txttu1.Text = dmcanbo_dal.SelectDMVEBOC("gtu1", dmveboc.Kyhieu);
                txttu2.Text = dmcanbo_dal.SelectDMVEBOC("gtu2", dmveboc.Kyhieu);
                txttu3.Text = dmcanbo_dal.SelectDMVEBOC("gtu3", dmveboc.Kyhieu);
                txttu4.Text = dmcanbo_dal.SelectDMVEBOC("gtu4", dmveboc.Kyhieu);
                txttu5.Text = dmcanbo_dal.SelectDMVEBOC("gtu5", dmveboc.Kyhieu);
                txttu6.Text = dmcanbo_dal.SelectDMVEBOC("gtu6", dmveboc.Kyhieu);
                txttu7.Text = dmcanbo_dal.SelectDMVEBOC("gtu7", dmveboc.Kyhieu);
                txttu8.Text = dmcanbo_dal.SelectDMVEBOC("gtu8", dmveboc.Kyhieu);
                txttu9.Text = dmcanbo_dal.SelectDMVEBOC("gtu9", dmveboc.Kyhieu);
                txttu10.Text = dmcanbo_dal.SelectDMVEBOC("gtu10", dmveboc.Kyhieu);
                txttu11.Text = dmcanbo_dal.SelectDMVEBOC("gtu11", dmveboc.Kyhieu);
                txttu12.Text = dmcanbo_dal.SelectDMVEBOC("gtu12", dmveboc.Kyhieu);
                txttu13.Text = dmcanbo_dal.SelectDMVEBOC("gtu13", dmveboc.Kyhieu);
                txttu14.Text = dmcanbo_dal.SelectDMVEBOC("gtu14", dmveboc.Kyhieu);
                txttu15.Text = dmcanbo_dal.SelectDMVEBOC("gtu15", dmveboc.Kyhieu);
                txttu16.Text = dmcanbo_dal.SelectDMVEBOC("gtu16", dmveboc.Kyhieu);
                txtnam1.Text = dmcanbo_dal.SelectDMVEBOC("gnam1", dmveboc.Kyhieu);
            }
            catch
            {

            }
        }
        private DMVETT_DAL dmcanbo_dal = new DMVETT_DAL();
        private void rpt_OnLoadComplete()
        {
            //    SplashScreenManager.CloseForm();
        }
        private void btnin_Click(object sender, EventArgs e)
        {
            if (!Kiemtraluu())
            {
                Luuketqua();

                rptbienbanboc5 rpt = new rptbienbanboc5();
                //rpt.OnLoadComplete += new rptbienbanboc5.OnLoadCompleteHandler(rpt_OnLoadComplete);
                //rpt.Parameters["pNgay"].Value = deNgay.DateTime;
                //rpt.Parameters["pKyhieu"].Value = txtkyhieu.Text.ToString().Trim();                
                rpt.ShowRibbonPreviewDialog();
            }
            else clsCommon.MsgBox("Kết quả bạn nhập vào bị thiếu", 1);
        }
        void Kiemtraso(string So)
        {
            int d1 = 0;
            int d2 = 0;
            int d3 = 0;
            int m = 0;
            string bien1 = "";
            string bien2 = "";
            string bien3 = "";
            string[] A = new string[23];
            A[1] = txtnhat1.Text.Trim();
            A[2] = txtnhat2.Text.Trim();
            A[3] = txtnhat3.Text.Trim();
            A[4] = txtnhat4.Text.Trim();
            A[5] = txtnhi1.Text.Trim();
            A[6] = txtba1.Text.Trim();
            A[7] = txttu1.Text.Trim();
            A[8] = txttu2.Text.Trim();
            A[9] = txttu3.Text.Trim();
            A[10] = txttu4.Text.Trim();
            A[11] = txttu5.Text.Trim();
            A[12] = txttu6.Text.Trim();
            A[13] = txttu7.Text.Trim();
            A[14] = txttu8.Text.Trim();
            A[15] = txttu9.Text.Trim();
            A[16] = txttu10.Text.Trim();
            A[17] = txttu11.Text.Trim();
            A[18] = txttu12.Text.Trim();
            A[19] = txttu13.Text.Trim();
            A[20] = txttu14.Text.Trim();
            A[21] = txttu15.Text.Trim();
            A[22] = txttu16.Text.Trim();
            if (So.Length == 4)
            {
                bien1 = So;
                bien2 = So.Substring(1, 3);
                bien3 = So.Substring(2, 2);
            }
            if (So.Length == 3)
            {
                bien2 = So;
                bien3 = So.Substring(1, 2);
            }
            if (So.Length == 2)
            {
                bien3 = So;
            }

            if (bien3 != null || bien3 != "")
            {
                for (int i = 1; i < A.Length; ++i)
                {
                    if (A[i] != "" && A[i].Length >= 2)
                    {
                        if (A[i].Length == 4)
                            m = 2;
                        else
                            if (A[i].Length == 3)
                                m = 1;
                            else
                                m = 0;

                        if (bien3 == A[i].Substring(m, 2))
                        {
                            d3 = d3 + 1;
                        }
                    }
                }
            }
            if (bien2 != null || bien2 != "")
            {
                for (int i = 1; i < A.Length; ++i)
                {
                    if (A[i] != "" && A[i].Length >= 3)
                    {
                        if (A[i].Length == 4)
                            m = 1;
                        else
                            if (A[i].Length == 3)
                                m = 0;
                        if (bien2 == A[i].Substring(m, 3))
                        {
                            d2 = d2 + 1;
                        }
                    }
                }
            }
            if (bien1 != null || bien1 != "")
            {
                for (int i = 1; i < A.Length; ++i)
                {
                    if (A[i] != "" && A[i].Length >= 4)
                    {
                        if (bien1 == A[i].Substring(0, 4))
                        {
                            d1 = d1 + 1;
                        }
                    }
                }
            }
            if (d1 >= 2 || d2 >= 2 || d3 >= 2)
            {
                clsCommon.MsgBox("Số này đã quay rồi, đề nghị quay số khác!", 0);
                clsCommon.MsgBox("Đề nghị quay lại số khác!", 1);
            }
        }
        private bool Kiemtraluu()
        {
            bool kq = false;
            string[] A = new string[24];
            A[1] = txtnhat1.Text.Trim();
            A[2] = txtnhat2.Text.Trim();
            A[3] = txtnhat3.Text.Trim();
            A[4] = txtnhat4.Text.Trim();
            A[5] = txtnhi1.Text.Trim();
            A[6] = txtba1.Text.Trim();
            A[7] = txttu1.Text.Trim();
            A[8] = txttu2.Text.Trim();
            A[9] = txttu3.Text.Trim();
            A[10] = txttu4.Text.Trim();
            A[11] = txttu5.Text.Trim();
            A[12] = txttu6.Text.Trim();
            A[13] = txttu7.Text.Trim();
            A[14] = txttu8.Text.Trim();
            A[15] = txttu9.Text.Trim();
            A[16] = txttu10.Text.Trim();
            A[17] = txttu11.Text.Trim();
            A[18] = txttu12.Text.Trim();
            A[19] = txttu13.Text.Trim();
            A[20] = txttu14.Text.Trim();
            A[21] = txttu15.Text.Trim();
            A[22] = txttu16.Text.Trim();
            A[23] = txtnam1.Text.Trim();
            for (int i = 1; i < 5; ++i)
            {
                if (A[i] == "" || A[i].Length < 4)
                {
                    kq = true;
                }
            }
            for (int i = 5; i < 7; ++i)
            {
                if (A[i] == "" || A[i].Length < 3)
                {
                    kq = true;
                }
            }
            for (int i = 7; i < 23; ++i)
            {
                if (A[i] == "" || A[i].Length < 2)
                {
                    kq = true;
                }
            }
            for (int i = 23; i < 24; ++i)
            {
                if (A[i] == "" || A[i].Length < 1)
                {
                    kq = true;
                }
            }
            return kq;
        }

        private void btndong_Click(object sender, EventArgs e)
        {
            if (!Kiemtraluu())
            {
                Luuketqua();
            }
            this.Close();
        }
        private void txtnhat1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txtnhat2.Focus();
                if (txtnhat1.Text.Trim() != "")
                {
                    Kiemtraso(txtnhat1.Text.Trim());
                }
            }
        }

        private void txtnhat2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txtnhat3.Focus();
                if (txtnhat2.Text.Trim() != "")
                {
                    Kiemtraso(txtnhat2.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txtnhat1.Focus();
        }

        private void txtnhat3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txtnhat4.Focus();
                if (txtnhat3.Text.Trim() != "")
                {
                    Kiemtraso(txtnhat3.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txtnhat2.Focus();
        }

        private void txtnhat4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txtnhi1.Focus();
                if (txtnhat4.Text.Trim() != "")
                {
                    Kiemtraso(txtnhat4.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txtnhat3.Focus();
        }

        private void txtnhi1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txtba1.Focus();
                if (txtnhi1.Text.Trim() != "")
                {
                    Kiemtraso(txtnhi1.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txtnhat4.Focus();
        }

        private void txtba1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu1.Focus();
                if (txtba1.Text.Trim() != "")
                {
                    Kiemtraso(txtba1.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txtnhi1.Focus();
        }

        private void txttu1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu2.Focus();
                if (txttu1.Text.Trim() != "")
                {
                    Kiemtraso(txttu1.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txtba1.Focus();
        }

        private void txttu2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu3.Focus();
                if (txttu2.Text.Trim() != "")
                {
                    Kiemtraso(txttu2.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu1.Focus();
        }

        private void txttu3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu4.Focus();
                if (txttu3.Text.Trim() != "")
                {
                    Kiemtraso(txttu3.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu2.Focus();
        }

        private void txttu4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu5.Focus();
                if (txttu4.Text.Trim() != "")
                {
                    Kiemtraso(txttu4.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu3.Focus();
        }

        private void txttu5_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu6.Focus();
                if (txttu5.Text.Trim() != "")
                {
                    Kiemtraso(txttu5.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu4.Focus();
        }

        private void txttu6_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu7.Focus();
                if (txttu6.Text.Trim() != "")
                {
                    Kiemtraso(txttu6.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu5.Focus();
        }

        private void txttu7_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu8.Focus();
                if (txttu7.Text.Trim() != "")
                {
                    Kiemtraso(txttu7.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu6.Focus();
        }

        private void txttu8_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu9.Focus();
                if (txttu8.Text.Trim() != "")
                {
                    Kiemtraso(txttu8.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu7.Focus();
        }

        private void txttu9_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu10.Focus();
                if (txttu9.Text.Trim() != "")
                {
                    Kiemtraso(txttu9.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu8.Focus();
        }

        private void txttu10_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu11.Focus();
                if (txttu10.Text.Trim() != "")
                {
                    Kiemtraso(txttu10.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu9.Focus();
        }

        private void txttu11_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu12.Focus();
                if (txttu11.Text.Trim() != "")
                {
                    Kiemtraso(txttu11.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu10.Focus();
        }

        private void txttu12_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu13.Focus();
                if (txttu12.Text.Trim() != "")
                {
                    Kiemtraso(txttu12.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu11.Focus();
        }

        private void txttu13_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu14.Focus();
                if (txttu13.Text.Trim() != "")
                {
                    Kiemtraso(txttu13.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu12.Focus();
        }

        private void txttu14_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu15.Focus();
                if (txttu14.Text.Trim() != "")
                {
                    Kiemtraso(txttu14.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu13.Focus();
        }

        private void txttu15_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txttu16.Focus();
                if (txttu15.Text.Trim() != "")
                {
                    Kiemtraso(txttu15.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu16.Focus();
        }

        private void txttu16_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                txtnam1.Focus();
                if (txttu16.Text.Trim() != "")
                {
                    Kiemtraso(txttu16.Text.Trim());
                }
            }
            if (e.KeyCode.ToString() == "Up")
                txttu15.Focus();
        }

        private void txtnam1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.ToString() == "Down" || e.KeyCode == Keys.Enter)
            {
                btnin.Focus();
            }
            if (e.KeyCode.ToString() == "Up")
                txttu16.Focus();
        }

        private void checktrungNhapSo(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                // Enter key pressed

                MaskedTextBox txt = (MaskedTextBox)sender;
                if (txt.Text.Length >= 2)
                {
                    string value = txt.Text.Substring(txt.Text.Length - 2, 2);
                    bool isValid = true;
                    foreach (var pair in lstQuaySo)
                    {
                        if (pair.Key != txt.Name && pair.Value == value)
                        {
                            isValid = false;
                            break;
                        }
                    }
                    if (isValid)
                    {
                        lstQuaySo[txt.Name] = value;
                        SendKeys.Send("{TAB}");
                    }
                    else
                    {
                        MessageBox.Show("Không được nhập 2 số cuối trùng");
                        txt.Text = "";
                        txt.Focus();
                    }
                }
            }
        }

        

       
    }
}